package com.juyu.miliao.authentication.dao.redis;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Repository
public class SmsSenderRedisDao {
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    public boolean isMember(String phone) {
        String temp = stringRedisTemplate.opsForValue().get("smsSender:"+phone);
        if(temp == null || temp.equals("") || temp.equals("null")){
            return false;
        }
		return true;
	}

	public void addSmsSender(String phone){
        stringRedisTemplate.opsForValue().set("smsSender:"+phone,phone,1, TimeUnit.MINUTES);
    }

//    public void addSmsSenderByEveryDay(String phone){
//        stringRedisTemplate.opsForZSet().incrementScore("senderEveryDay",phone,1);
//    }
//
//    public Double scoreSmsSenderEveryDay(String phone){
//        return stringRedisTemplate.opsForZSet().score("senderEveryDay",phone);
//    }

    public Boolean isMemberBlacklist(String phone){
        return stringRedisTemplate.opsForSet().isMember("senderBlackList",phone);
    }
}
